package cn.ecut.dzy.one.single;

/**
 * @program: java-interview
 * @description: 懒汉式
 * 懒汉式：
 * 延迟创建这个实例对象
 * <p>
 * (1)构造器私有化
 * (2)用一个静态变量保存这个唯一的实例
 * (3)提供一个静态方法，获取这个实例对象
 * @author: DingZhenYun
 * @create: 2021-10-21 18:08
 **/

public class Singleton5 {
    //线程安全(使用于多线程)
    private static Singleton5 singleton5;

    private Singleton5() {
    }

    public static Singleton5 getInstance() throws InterruptedException {
        if (singleton5 == null) {
            synchronized (Singleton5.class) {
                if (singleton5 == null) {
                    Thread.sleep(100);
                    singleton5 = new Singleton5();
                }
            }
        }
        return singleton5;
    }
}
